package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.yuejianapp14.Activity.Adapter.UserCollectedAdapter;
import com.example.yuejianapp14.Activity.JavaBean.Collected;
import com.example.yuejianapp14.Activity.Listener.CollectedListener;
import com.example.yuejianapp14.Activity.Model.CollectedModel;
import com.example.yuejianapp14.R;

import java.util.List;

public class UserCollectedActivity extends AppCompatActivity {
    private SharedPreferences sp;
    private RecyclerView recyclerView;
    private Context mContext;
    private ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_collected);
        initViews();
        getData();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    public void initViews() {
        recyclerView = (RecyclerView)findViewById(R.id.rv_user_tiezi);
        recyclerView.setLayoutManager(new LinearLayoutManager((mContext)));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        sp=getSharedPreferences("uid",MODE_PRIVATE);
        back = (ImageView) findViewById(R.id.back);
    }
    CollectedListener findCollectedListener = new CollectedListener() {
        @Override
        public void onResponse(List<Collected> beanList) {
            UserCollectedAdapter adapter = new UserCollectedAdapter(UserCollectedActivity.this,beanList);
            recyclerView.setAdapter(adapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };

    public void getData() {
        CollectedModel collectedModel = new CollectedModel();
        collectedModel.findCollected(sp.getString("uid",""), findCollectedListener);
    }
}
